package com.example.forum.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.forum.commons.tools.Utils;
import com.example.forum.entity.TUsers;
import com.example.forum.enums.LoginResults;
import com.example.forum.mapper.TUsersMapper;
import com.example.forum.service.ITUsersService;
import org.springframework.stereotype.Service;

import static com.example.forum.commons.tools.Utils.md5Encoding;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author why
 * @since 2019-10-30
 */
@Service
public class TUsersServiceImpl extends ServiceImpl<TUsersMapper, TUsers> implements ITUsersService {
    public LoginResults CheckUserNameAndPassword(String username, String password) {

        TUsers dto=	super.getOne(new QueryWrapper<TUsers>().eq("username", username));
        if(dto!=null)
        {
            String md5pass=	md5Encoding(md5Encoding(password)+dto.getSalt());
            if(md5pass.equals(dto.getPassword()))
            {
                return LoginResults.Success;

            }else {
                return  LoginResults.PassWordError;
            }
        }else {

            return LoginResults.NotExist;
        }

    }
}
